package com.sgb.kjwl.viewmodel.demand;

import android.util.Log;
import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.supplier3.DictEntity3;
import com.sgb.kjwl.repository.HomeRepertory;
import com.sgb.kjwl.view.ui.activity.demand.DemandHallActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class DemandHallModel extends BaseViewModel {
    private DemandHallActivity activity;
    private HomeRepertory repertory;
    public DemandHallModel(DemandHallActivity activity, HomeRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }

//    获取材料类型数据
    public void getDemandHallList() {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(false);
        APIManager.getInstance().getCommonAPI().getDemandHall("").enqueue(new Callback<BaseEntity<List<DictEntity3>>>() {
            @Override
            public void onResponse(Call<BaseEntity<List<DictEntity3>>> call, Response<BaseEntity<List<DictEntity3>>> response) {
//                Log.e("tag数据","数据大小："+response.body().getData().size()+"数据状态："+response.body().getState() );
                DialogHelper.dismissProgressDialog();
                if (response.body() == null)
                    return;
                if (response.body().getState().equals(APIManager.RESPONSE_OK)) {
                    if (response.body().getData() == null)
                        return;
                    activity.getDemanHallTabList(response.body().getData());
                } else {
                    MToast.showToast(activity, response.message());
                }
            }

            @Override
            public void onFailure(Call<BaseEntity<List<DictEntity3>>> call, Throwable t) {
//                Log.e("tag数据失败","数据异常："+t.getMessage()+t.toString() );
                DialogHelper.dismissProgressDialog();
                MToast.showToast(activity, t.getMessage());
            }
        });
    }
}
